#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
调试路径问题
"""

import os
from pathlib import Path

def debug_paths():
    """调试路径问题"""
    print("=== 路径调试信息 ===")
    
    # 当前工作目录
    cwd = Path.cwd()
    print(f"当前工作目录: {cwd}")
    
    # 脚本所在目录
    script_dir = Path(__file__).parent
    print(f"脚本所在目录: {script_dir}")
    
    # 尝试多种路径
    possible_paths = [
        "agent-mcp/Ansible",
        cwd / "agent-mcp/Ansible",
        script_dir / "agent-mcp/Ansible",
        script_dir.parent / "agent-mcp/Ansible",
    ]
    
    print("\n=== 检查可能的路径 ===")
    for i, path in enumerate(possible_paths, 1):
        exists = path.exists()
        print(f"{i}. {path}")
        print(f"   存在: {exists}")
        if exists:
            print(f"   类型: {'目录' if path.is_dir() else '文件'}")
            if path.is_dir():
                try:
                    items = list(path.iterdir())
                    print(f"   内容: {len(items)} 个项目")
                    for item in items[:5]:  # 只显示前5个
                        print(f"     - {item.name}")
                    if len(items) > 5:
                        print(f"     ... 还有 {len(items) - 5} 个项目")
                except Exception as e:
                    print(f"   读取错误: {e}")
        print()
    
    # 检查最新的日期目录
    print("=== 检查最新日期目录 ===")
    for path in possible_paths:
        if path.exists() and path.is_dir():
            try:
                # 获取所有日期文件夹
                date_dirs = [d for d in path.iterdir() if d.is_dir() and d.name.isdigit()]
                if date_dirs:
                    # 按名称排序，获取最新的
                    latest_dir = sorted(date_dirs, key=lambda x: x.name, reverse=True)[0]
                    print(f"最新日期目录: {latest_dir}")
                    
                    # 获取脚本文件
                    script_files = list(latest_dir.glob("*.sh"))
                    print(f"脚本文件数量: {len(script_files)}")
                    for script in script_files:
                        print(f"  - {script.name}")
                    break
            except Exception as e:
                print(f"检查目录时出错: {e}")

if __name__ == "__main__":
    debug_paths() 